package com.yf.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;
import com.yf.dto.Article;
import com.yf.dto.ContentFileWithTitle;
import com.yf.entity.CmsCategory;
import com.yf.entity.CmsContent;
import com.yf.service.ArticleService;
import com.yf.service.CategoryService;
import com.yf.service.ContentFileService;

@Controller
@RequestMapping("/index")
public class IndexController {
	@Autowired
	private ArticleService articleService;
	@Autowired
	private CategoryService categoryService;
	@Autowired
	private ContentFileService contentFileService;
	
	@RequestMapping("")
	private ModelAndView index() {
		ModelAndView mv=new ModelAndView();
		List<Article> articleList=articleService.getArticle(1, 10);
		PageInfo<CmsContent> pageInfo1=articleService.getArticle(1,1, 10);
		CmsCategory category1=categoryService.getCategoryById(1);
		PageInfo<CmsContent> pageInfo2=articleService.getArticle(2,1, 10);
		CmsCategory category2=categoryService.getCategoryById(2);
		List<ContentFileWithTitle> contentFileList=contentFileService.getContentFile();
		mv.addObject("pageInfo1", pageInfo1);
		mv.addObject("category1", category1);
		mv.addObject("pageInfo2", pageInfo2);
		mv.addObject("category2", category2);
		mv.addObject("article", articleList);
		mv.addObject("contentFile", contentFileList);
		mv.setViewName("index");
		return mv;
	}
}
